package com.xiefengf.rabbitmq.producer.service;

import cn.hutool.json.JSONUtil;
import com.xiefengf.rabbitmq.producer.utils.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @author xiefengf
 * @version 1.0
 * @date 2024/1/10 23:58
 *
 * RabbitMQ基础 - Topic方式
 *
 */
@Service
public class TopicProductService {

    @Resource(name = "RabbitTemplate")
    private RabbitTemplate rabbitTemplate;

    /**
     * 下订单服务 - 只发送短信
     * @param userId
     * @param productId
     * @param msg
     */
    public void makeOrder1(Integer userId,Integer productId,String msg){
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("productId",productId);
        map.put("topic_1_msg",msg);
        rabbitTemplate.convertAndSend(StringUtils.TOPIC_EXCHANGE_NAME,"AAA.sms.BBB", JSONUtil.toJsonStr(map));
    }

    /**
     * 下订单服务 - 发送微信/邮件/微信
     * @param userId
     * @param productId
     * @param msg
     */
    public void makeOrder2(Integer userId,Integer productId,String msg){
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("productId",productId);
        map.put("topic_2_msg",msg);
        rabbitTemplate.convertAndSend(StringUtils.TOPIC_EXCHANGE_NAME,"weixin.sms.email", JSONUtil.toJsonStr(map));
    }

    /**
     * 下订单服务 - 发送邮件/微信
     * @param userId
     * @param productId
     * @param msg
     */
    public void makeOrder3(Integer userId,Integer productId,String msg){
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("productId",productId);
        map.put("topic_3_msg",msg);
        rabbitTemplate.convertAndSend(StringUtils.TOPIC_EXCHANGE_NAME,"weixin.email", JSONUtil.toJsonStr(map));
    }


}
